import argparse
from urllib3.util import parse_url

desc = '''Starting program with parameters'''


class ValidateUrl(argparse.Action):
    def __call__(self, parser, namespace, values, option_string=None):
        if not self.__validate(values):
            parser.error(f"Please enter a valid URL. Got: {values}")
        setattr(namespace, self.dest, values)

    def __validate(self, url) -> bool:
        try:
            result = parse_url(url)
            return all([result.scheme, result.netloc])
        except:
            return False

class ArgParser:
    def __init__(self) -> None:
        self.parser = argparse.ArgumentParser(description=desc)
        self.args = None
        self.parser.add_argument(
                "--link", default=None,
                help="Insert youtube video URL",
                action=ValidateUrl,
                type=str
        )
    
    def parse(self):
        self.args = self.parser.parse_args()

